package com.example.questions.controller;


import com.example.questions.entity.InterviewQuestions;
import com.example.questions.service.InterviewQuestionsService;
import com.github.pagehelper.PageInfo;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * (InterviewQuestions)表控制层
 *
 * @author makejava
 * @since 2023-07-01 10:06:13
 */
@RestController
@RequestMapping("interview/questions")
public class InterviewQuestionsController {
    /**
     * 服务对象
     */
    @Resource
    private InterviewQuestionsService interviewQuestionsService;

    /**
     * 分页查询
     *
     * @param interviewQuestions 筛选条件
     * @return 查询结果
     */
    @PostMapping("/list")
    public ResponseEntity<PageInfo<InterviewQuestions>> queryByPage(@RequestBody InterviewQuestions interviewQuestions,
                                                                    @RequestParam(defaultValue = "1", required = false) Integer page,
                                                                    @RequestParam(defaultValue = "10", required = false) Integer size) {
        return ResponseEntity.ok(this.interviewQuestionsService.queryByPage(interviewQuestions, page, size));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<InterviewQuestions> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.interviewQuestionsService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param interviewQuestions 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<InterviewQuestions> add(@RequestBody InterviewQuestions interviewQuestions) {
        return ResponseEntity.ok(this.interviewQuestionsService.insert(interviewQuestions));
    }

    /**
     * 编辑数据
     *
     * @param interviewQuestions 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<InterviewQuestions> edit(@RequestBody InterviewQuestions interviewQuestions) {
        return ResponseEntity.ok(this.interviewQuestionsService.update(interviewQuestions));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Integer id) {
        return ResponseEntity.ok(this.interviewQuestionsService.deleteById(id));
    }

    @GetMapping("/queryCount")
    public ResponseEntity<Integer> queryCount(){
        return ResponseEntity.ok(this.interviewQuestionsService.queryCount());
    }

}

